package classificator;

import classificator.data.Data;
import classificator.data.DataException;
import classificator.tree.DecisionTree;

import java.io.FileNotFoundException;
import java.io.IOException;

/**TODO CLIENT
 *
 * @author 467644
 */
class MainTest {
    public static void main(String[] args) {
        System.out.println("1. Learn Decision tree");
        System.out.println("2. Use decision tree (from tree.dat)");
        System.out.println("Please make an option: ");
        int scelta = 1;
        String nomeFile = "tree.dat";
        DecisionTree tree;
        switch (scelta){
            case 1:
                try {
                    //Apprende un nuovo albero e lo salva in un file
                    tree = new DecisionTree(new Data("playtennis"));
        
                    //tree.printRules();
                    //TODO:cambiare tostring di printtree
                    tree.toString();
                    try {
                        tree.salva(nomeFile);
                        //System.out.println("tree.dat salvato");
                    } catch (FileNotFoundException ex) {
                        ex.printStackTrace();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                } catch (DataException ex) {
                    System.err.println(ex.getMessage());
                }
                break;
            case 2:
                //Carica un albero appreso e permette di classiicare nuovi esempi
                try {
                    tree = DecisionTree.carica(nomeFile);
                    //TODO classificare nuovi esempi(?)
                    tree.printRules();
//                    try{
//                        System.out.println(tree.predictedClass());
//                    } catch (UnknownValueException uve){
//                        System.err.println(uve.getMessage());
//                    }
                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                } catch (IOException ex) {
                    ex.printStackTrace();
                } catch (ClassNotFoundException ex) {
                    ex.printStackTrace();
                }
                break;
            default:
                System.out.println("Scelta non valida");
        }
        
        
        
    }
}